######################################################################
# Time-stamp: <2004-02-25 20:35:47 patrick>
#
# Data Selection dynamic data routines
######################################################################
package EP::EPC::Interface::Data_Selection;
use strict;

use EP::Legacy::EPDATA;
use EP::EPC::Interface;
use EP::Config;

=head1 NAME

EPC_DD::Data_Selection

=head1 SYNOPSIS

=head1 DESCRIPTION

=head1 METHODS

=over

=back

=cut

my $DATA_UPLOAD_EPC_ID; # To be retrieved from the database!!

sub newDD {
  my $proto = shift;
  my $ep_query_doc = shift;
  my $query = shift;
  my $DDD = shift;

  my $class = ref($proto) || $proto;
  my $self  = {};
  bless $self, $class;

  $self->initialize($ep_query_doc, $query, $DDD);
  return $self;
}

sub initialize {
  my $self = shift;
  $self->{epc_query} = shift;
  $self->{query} = shift;
  $self->{DDD} = shift;

  $DATA_UPLOAD_EPC_ID = 1; # TODO: from database!

  return;
}

#sub list_available_sources {
#    my $self = shift;

#    my $uploads = { 0 => { key => "Uploads",
#			   value => "session uploads" },
#		    1 => { key => $self->{DDD}->get_username(),
#			   value => "default folder" }
#    };

#  my $dl = &EP::EPC::Interface::DD::dynamic_list ( $uploads );
#  return $dl->findnodes('/*');
#}

# sub list_datasets {
#   my $self = shift;
#   my $user_folder = shift || $self->{DDD}->get_username();
#   my $HierClustHACK = shift;
#   my $session;

#   if ( EP::Common::DB::session_data_only( $self->{DDD}->get_username() ) == 1 ) {
#     $session = $self->{DDD}->get_session_id();
#   }

#   my $data = { folder => $user_folder,
# 	       username => $self->{DDD}->get_username(),
# 	       session => $session
# 	     };

#   my $dataset = EP::Common::DB::ex_get_dataset ( $data );

#   foreach my $dataset_key ( keys %$dataset ) {
#     delete $dataset->{$dataset_key} and next if not $dataset->{$dataset_key}->{dataset_name};

#     ########### VERY QUICK AND UGLY HACK TO GET IT TO WORK WITH OLD
#     ########### EPCLUST HIERARCHICAL CLUSTERING INTERFACE #######
#     $dataset->{$dataset_key}{key} = $dataset->{$dataset_key}{filename} if $HierClustHACK;
#     $dataset->{$dataset_key}->{href} = $EP::Config::h->{EPNG_USRDATA_URL} . "/" . $dataset->{$dataset_key}->{folder} . "/" . $dataset->{$dataset_key}->{filename};
#     $dataset->{$dataset_key}->{row} = "<a target=\"_blank\" href=\"" . $EP::Config::h->{EPNG_USRDATA_URL} . "/" . $dataset->{$dataset_key}->{folder} . "/" . $dataset->{$dataset_key}->{filename} . ".rows\">rows</a>";
#     $dataset->{$dataset_key}->{col} = "<a target=\"_blank\" href=\"" . $EP::Config::h->{EPNG_USRDATA_URL} . "/" . $dataset->{$dataset_key}->{folder} . "/" . $dataset->{$dataset_key}->{filename} . ".columns\">cols</a>";

#     foreach ( keys %{$dataset->{$dataset_key}} ) {
#       delete $dataset->{$dataset_key}->{$_}
# 	unless
# 	  /^name$/
#        or /^key$/
#        or /^value$/
#        or /^row$/
#        or /^col$/
#        or /^href$/;
#     }
#   }

#   my $dl = &EP::EPC::Interface::DD::dynamic_list ( $dataset );
#   return $dl->findnodes('/*');
# }

#sub list_dataset_sources {
#  my $self = shift;
#  my $source = shift;
#  my ($data);
#  my $session;

#  if ( $source =~ /uploads/i ) {
#      $data = { session => $self->{DDD}->get_session_id(),
#		folder => "uploads",
#		username => $self->{DDD}->get_username()
#		};
#  } else {
#      if (  &EP::Common::DB::session_data_only( $self->{DDD}->get_username() ) == 1 ) {
#	  $session = $self->{DDD}->get_session_id();
#      }

#      $data = { session => $session,
#		folder => $self->{DDD}->get_username(),
#		username => $self->{DDD}->get_username()
#		};
#      if ( $source =~ /all/i ) { 
#	  # need to get this done properly...
#	  $data->{all_folders} = 1;
#	  $data->{session} = $self->{DDD}->get_session_id();
#      };
#  }

#  my $dataset = &EP::Common::DB::get_dataset( $data );

#  foreach my $dataset_key ( keys %$dataset ) {
#     foreach ( keys %{$dataset->{$dataset_key}} ) {
#      delete $dataset->{$dataset_key}->{$_}
#	unless
#	  /^name$/
#       or /^key$/
#       or /^value$/;
#    }
#  }

#  my $dl = &EP::EPC::Interface::DD::dynamic_list( $dataset );
#  return $dl->findnodes ('/*');
#}

1;
